home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / Waste TCL r2 / CWASTEDlgText.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  5.6 KB  |  240 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CWASTEDlgText.c
  3.  
  4.     A class with some of the functionality of CDialogText, but using CWASTEText
  5.  
  6.  ******************************************************************************/
  7.  
  8. #ifdef TCL_PCH
  9. #include <TCLHeaders>
  10. #endif
  11.  
  12. #include "CWASTEDlgText.h"
  13. #include "CDialog.h"
  14. #include <CPaneBorder.h>
  15. #include "CBartender.h"
  16. #include "Constants.h"
  17.  
  18. #define kBorderAmount    2    // white space between border and text of edit field
  19.  
  20. extern CBartender    *gBartender;
  21. extern CBureaucrat        *gGopher;        // First in line to get commands
  22.  
  23. static pascal void WEPostUpdate(WEHandle hWE, long fixLength, long inputAreaStart,
  24.     long inputAreaEnd, long pinRangeStart, long pinRangeEnd);
  25.  
  26. extern CWASTEText    *gWASTEText;                /* Current WASTEText object */
  27.  
  28. TCL_DEFINE_CLASS_D1(CWASTEDlgText, CWASTEText);
  29.  
  30.  
  31. /********************************************************\
  32.  CWASTEDlgText - default constructor
  33. \********************************************************/
  34.  
  35. CWASTEDlgText::CWASTEDlgText()
  36. {
  37.     TCL_END_CONSTRUCTOR
  38. }
  39.  
  40.  
  41. /********************************************************\
  42.  CWASTEDlgText - constructor
  43. \********************************************************/
  44.  
  45. CWASTEDlgText::CWASTEDlgText(
  46.     CView            *anEnclosure,
  47.     CView            *aSupervisor,
  48.     short            aWidth,
  49.     short            aHeight,
  50.     short            aHEncl,
  51.     short            aVEncl,
  52.     SizingOption    aHSizing,
  53.     SizingOption    aVSizing,
  54.     short            aLineWidth,
  55.     Boolean            aScrollHoriz,
  56.     Boolean            aIsRequired,
  57.     long            aMaxValidLength,
  58.     Boolean            aValidateOnResign)
  59.  
  60.     : CWASTEText(anEnclosure, aSupervisor,
  61.         aWidth, aHeight, aHEncl, aVEncl,
  62.         aHSizing, aVSizing, aLineWidth, aScrollHoriz)
  63. {
  64.  
  65.     IWASTEDlgTextX();
  66.     TCL_END_CONSTRUCTOR
  67. }
  68.  
  69.  
  70. /********************************************************\
  71.  ~CWASTEDlgText - destructor
  72. \********************************************************/
  73.  
  74. CWASTEDlgText::~CWASTEDlgText()
  75. {
  76.     TCL_START_DESTRUCTOR
  77. }
  78.  
  79.  
  80. /********************************************************\
  81.  IWASTEDlgText - initializer, if used with default
  82.      constructor
  83. \********************************************************/
  84.  
  85. void CWASTEDlgText::IWASTEDlgText(CView *anEnclosure, CView *aSupervisor,
  86.                 short aWidth, short aHeight,
  87.                 short aHEncl, short aVEncl,
  88.                 SizingOption aHSizing, SizingOption aVSizing,
  89.                 short aLineWidth)
  90. {
  91.  
  92.     CWASTEText::IWASTEText(anEnclosure, aSupervisor,
  93.         aWidth, aHeight, aHEncl, aVEncl,
  94.         aHSizing, aVSizing, aLineWidth);
  95.  
  96.     IWASTEDlgTextX();
  97. }
  98.  
  99.  
  100. /********************************************************\
  101.  IViewTemp - construct from View resource
  102. \********************************************************/
  103.  
  104. void CWASTEDlgText::IViewTemp(CView *anEnclosure, CBureaucrat *aSupervisor,
  105.                             Ptr viewData)
  106. {
  107.     CWASTEText::IViewTemp(anEnclosure, aSupervisor, viewData);
  108.  
  109.     IWASTEDlgTextX();
  110. }
  111.  
  112.  
  113. /********************************************************\
  114.  IWASTEDlgTextX - common initialization
  115. \********************************************************/
  116.  
  117. void CWASTEDlgText::IWASTEDlgTextX()
  118. {
  119.     WETSMPostUpdateProcPtr postProc;
  120.  
  121.     MakeBorder();
  122.     SetWholeLines(FALSE);
  123.     
  124.     // set postupdate routine to WEPostUpdate
  125.     postProc = &WEPostUpdate;
  126.     WESetInfo(weTSMPostUpdate, (Ptr)&postProc, macWE);
  127. }
  128.  
  129. /********************************************************\
  130.  WEPostUpdate -- broadcast a dialog text changed message
  131. \********************************************************/
  132.  
  133. static pascal void WEPostUpdate(WEHandle hWE, long fixLength, long inputAreaStart,
  134.     long inputAreaEnd, long pinRangeStart, long pinRangeEnd)
  135. {
  136.     short ID;
  137.     GrafPtr curPort;
  138.     if (gWASTEText != NULL)
  139.     {
  140.         GetPort(&curPort);
  141.         ID = gWASTEText->ID;
  142.         gWASTEText->BroadcastChange(dialogTextChanged, &ID);
  143.         SetPort(curPort);
  144.         gWASTEText->Prepare();
  145.     }
  146. }
  147.  
  148.  
  149. /********************************************************\
  150.  MakeBorder - put a border around the text
  151. \********************************************************/
  152.  
  153. void CWASTEDlgText::MakeBorder()
  154. {
  155.     Rect    margin;
  156.     CPaneBorder *border;
  157.  
  158.     border = TCL_NEW(CPaneBorder,());
  159.     border->IPaneBorder(kBorderFrame);
  160.     SetRect(&margin, -kBorderAmount, -kBorderAmount, kBorderAmount, kBorderAmount);
  161.     border->SetMargin(&margin);
  162.     SetBorder(border);
  163. }
  164.  
  165. /********************************************************\
  166.  DoKey - handle Tab and Return
  167. \********************************************************/
  168.  
  169. void CWASTEDlgText::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
  170. {
  171.     Boolean pass = TRUE;
  172.     short    ID;
  173.  
  174.     switch (theChar)
  175.     {
  176.         case '\t':
  177.         case '\r':
  178.         case kEnterKey:
  179.             pass = FALSE;
  180.             break;
  181.  
  182.         case kEscapeOrClear:
  183.             if (keyCode == KeyEscape) pass = FALSE;
  184.             break;
  185.     }
  186.     if (pass)
  187.     {
  188.         CWASTEText::DoKeyDown(theChar, keyCode, macEvent);
  189.  
  190.         if (itsTypingTask && itsTypingTask->CanStillType())
  191.         {
  192.             ID = this->ID;
  193.             BroadcastChange(dialogTextChanged, &ID);
  194.         }
  195.     }
  196.     else
  197.         itsSupervisor->DoKeyDown(theChar, keyCode, macEvent);
  198. }
  199.  
  200. /********************************************************\
  201.  GetTextString - return the text as a pascal string
  202. \********************************************************/
  203.  
  204. void CWASTEDlgText::GetTextString(StringPtr aString)
  205. {
  206.     short length = Min(GetLength(), 255);
  207.  
  208.     StopInlineSession();
  209.     BlockMove(*GetTextHandle(), &aString[1], length);
  210.     aString[0] = length;
  211. }
  212.  
  213. /********************************************************\
  214.  PerformEditCommand - handle cut, copy, paste, and clear
  215.      -- check for text changed
  216. \********************************************************/
  217.  
  218. void CWASTEDlgText::PerformEditCommand(long theCommand)
  219. {
  220.     short    ID;
  221.  
  222.     CWASTEText::PerformEditCommand(theCommand);
  223.  
  224.     switch( theCommand)
  225.     {        
  226.         case cmdCut:
  227.         case cmdPaste:
  228.         case cmdClear:
  229.             ID = this->ID;
  230.             BroadcastChange(dialogTextChanged, &ID);
  231.             break;
  232.         
  233.         default:
  234.             break;
  235.     }
  236.  
  237. }
  238.  
  239.  
  240.